package comc.config;



import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * @Author 徐本锡
 **/
@Configuration
public class WebAppConfiguration implements WebMvcConfigurer  {

    /**
     * 配置静态资源
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String path= "/";
        for(int i=1900; i<=2500; i++){
            path = String.valueOf(i);
            registry.addResourceHandler("/"+path+"/**").addResourceLocations("file:C:/"+path+"/");
            registry.addResourceHandler("/"+path+"/**").addResourceLocations("file:/"+path+"/");
        }
    }

    /**
     * 跨域支持
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods("GET", "POST", "DELETE", "PUT", "PATCH")
                .maxAge(3600 * 24);
    }

    /**
     * 添加拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截路径可自行配置多个 可用 ，分隔开
        System.out.println("web进入拉进去");
        registry.addInterceptor(new JwtInterceptor()).addPathPatterns("/user/**").excludePathPatterns("/Logon");
    }


}